Skip to content

Conversation

@bedrin
Copy link
Contributor

@bedrin bedrin commented Oct 31, 2025

This PR migrates Spring AI framework to Spring Boot 4.0.0.RC1
Depending on Spring AI release schedule and planning it should probably be targeted to 2.x dedicated branch (or dedicated 1.1.x branch should be created) since it will break compatibility with Spring Boot 3.5

  • Updated Spring Boot dependency to 4.0.0.RC1
  • Spring Framework 7 API compatibility (see below)
  • Migration to Spring Boot 4.x as per https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide
    • Adopt new modular design of starters
    • Use new Jackson 3.x API partially - some classes like JsonSchemaGenerator depend on Jackson 2.x for now
    • Support Property Mapper API changes around null handling
    • Use Spring Framework Retry functionality instead of separate Spring Retry project
  • Updated Swagger codegen templates used by huggingface model to align with latest Spring Framework APIs
  • Update elasticsearch test container to 9.2.0
  • Added FailureDetectingExternalResource from old versions of testcontainers library to support gemfire-testcontainers
  • Other related dependencies updates:
    • TestContainers to 2.0.1
    • GemFire testcontainers to 2.3.3
    • opensearch-testcontainers to 4.0.0
    • Rest Assured to 5.5.6
    • swagger-codegen-maven-plugin to 3.0.75

Fixes GH-3379 (#3379)

Includes changes from #4681

Built on-top of #4771

  • Use only Spring Framework APIs available both in 6.x and 7.x branches
  • Add constructors without logic to *Api classes in models modules to simplify extensibility; effective final fields are marked as final
  • Kotlin 2.x support; use kotlin compiler version 2.2.21

Future tasks:

@ilayaperumalg
Copy link
Member

ilayaperumalg commented Oct 31, 2025

Hi @bedrin, Thanks for the PR. But, we already have an existing draft PR #4681 from @paulbakker addressing the same. It would be nice to collaborate on a single PR to avoid duplicate efforts.

@bedrin
Copy link
Contributor Author

bedrin commented Oct 31, 2025

@ilayaperumalg thanks - I've missed it. I've merged #4681 into my branch, resolved conflicts and squashed everything as per contributing guidelines. Tests are green locally.

@paulbakker I've merged your branch into mine - we did almost the same :) but you also made an extra step with Spring Retry. The diff between our branches is shown here (after I've resolved conflicts): OncoSteps#1 . Appreciate your review

- Updated Spring Boot dependency to 4.0.0.RC1
- Spring Framework 7 API compatibility (see below)
- Migration to Spring Boot 4.x as per https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide :
  * Adopt new modular design of starters
  * Use new Jackson 3.x API
  * Support Property Mapper API changes around null handling
  * Migrated from Spring Retry to Spring Framework Retry functionality
- Updated Swagger codegen templates used by huggingface model to align with latest Spring Framework APIs
- Update elasticsearch test container to 9.2.0
- Added `FailureDetectingExternalResource` from old versions of `testcontainers` library to support `gemfire-testcontainers`
- Other related dependencies updates:
  * TestContainers to 2.0.1
  * GemFire testcontainers to 2.3.3
  * opensearch-testcontainers to 4.0.0
  * Rest Assured to 5.5.6
  * swagger-codegen-maven-plugin to 3.0.75

Fixes spring-projectsGH-3379 (spring-projects#3379)

Includes changes by @paulbakker from spring-projects#4681

Built on-top of spring-projects#4771
- Use only Spring Framework APIs available both in 6.x and 7.x branches
- Add constructors without logic to `*Api` classes in `models` modules to simplify extensibility; effective final fields are marked as final
- Kotlin 2.x support; use kotlin compiler version 2.2.21
- Update MCP SDK to 0.15.0
- Update MCP Annotations to 0.6.0

Future tasks:
- [x] Raise issue to migrate from Spring Retry to Spring Framework 7 built-in retry functionality: spring-projects#4681
- [ ] Raise issue with `swagger-codegen-maven-plugin` to support Spring Framework 7
- [x] Raise issue with GemFire to support testcontainers 2.x: gemfire/gemfire-testcontainers#7

Signed-off-by: Dmitry Bedrin <dmitry.bedrin@gmail.com>
@bedrin bedrin force-pushed the feature/spring-boot-4-support branch from bd3fd81 to 65d0ae6 Compare October 31, 2025 13:55
@paulbakker
Copy link
Contributor

Changes look ok, although it's kinda hard to review - so we mostly have to rely on the tests to pass.

@ilayaperumalg ilayaperumalg added this to the 2.0.0.M1 milestone Nov 4, 2025
…-4-support

Signed-off-by: Dmitry Bedrin <dmitry.bedrin@gmail.com>

# Conflicts:
#   auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-webflux/src/test/java/org/springframework/ai/mcp/server/autoconfigure/McpServerSseWebFluxAutoConfigurationTests.java/McpServerSseWebFluxAutoConfigurationTests.java
#	auto-configurations/models/spring-ai-autoconfigure-model-anthropic/src/test/java/org/springframework/ai/model/anthropic/autoconfigure/BaseAnthropicIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-deepseek/src/test/java/org/springframework/ai/model/deepseek/autoconfigure/BaseDeepSeekIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-elevenlabs/src/test/java/org/springframework/ai/model/elevenlabs/autoconfigure/ElevenLabsITUtil.java
#	auto-configurations/models/spring-ai-autoconfigure-model-google-genai/src/test/java/org/springframework/ai/model/google/genai/autoconfigure/chat/tool/FunctionCallWithFunctionBeanIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-minimax/src/test/java/org/springframework/ai/model/minimax/autoconfigure/FunctionCallbackInPromptIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-minimax/src/test/java/org/springframework/ai/model/minimax/autoconfigure/FunctionCallbackWithPlainFunctionBeanIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-minimax/src/test/java/org/springframework/ai/model/minimax/autoconfigure/MiniMaxAutoConfigurationIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-minimax/src/test/java/org/springframework/ai/model/minimax/autoconfigure/MiniMaxFunctionCallbackIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-minimax/src/test/java/org/springframework/ai/model/minimax/autoconfigure/MiniMaxPropertiesTests.java
#	auto-configurations/models/spring-ai-autoconfigure-model-minimax/src/test/java/org/springframework/ai/model/minimax/autoconfigure/MinimaxModelConfigurationTests.java
#	auto-configurations/models/spring-ai-autoconfigure-model-mistral-ai/src/test/java/org/springframework/ai/model/mistralai/autoconfigure/MistralAiOcrPropertiesTests.java
#	auto-configurations/models/spring-ai-autoconfigure-model-ollama/src/test/java/org/springframework/ai/model/ollama/autoconfigure/BaseOllamaIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/ChatClientAutoConfigurationIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/OpenAiAutoConfigurationIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/OpenAiModelConfigurationTests.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/OpenAiPropertiesTests.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/OpenAiResponseFormatPropertiesTests.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/tool/FunctionCallbackInPrompt2IT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/tool/FunctionCallbackInPromptIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/tool/FunctionCallbackWithPlainFunctionBeanIT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/tool/OpenAiFunctionCallback2IT.java
#	auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/tool/OpenAiFunctionCallbackIT.java
@bedrin
Copy link
Contributor Author

bedrin commented Nov 7, 2025

I've resolved merge conflicts and pushed the changes again

@sdeleuze
Copy link
Contributor

sdeleuze commented Nov 17, 2025

From the quick look I had, this PR looks like a good starting point to introduce Spring Boot 4.0 support in Spring AI 2.0 snapshots.

I would advise to update the reference documentation and README of each branch to clarify that:

  • Spring AI 1.x is for Spring Boot 3.x
  • Spring AI 2.x will be for Spring Boot 4.x

@tzolov tzolov self-assigned this Nov 18, 2025
@tzolov
Copy link
Contributor

tzolov commented Nov 18, 2025

@bedrin, @paulbakker excellent work! Really appreciate the effort. This will help us bootstrap the migration work toward spring 7 and boot 4.

I've rebased, fixed the remaining conflicts and issues adjusted some version (for example openserch-testcontainers had to be reverted to 2.x.x version to support Java 17) in a working branch is https://github.com/tzolov/spring-ai/tree/gh-4774-pr

We are going ahead in merging it today.

(N.B. I will add @paulbakker as co-author to @bedrin's PR)

tzolov pushed a commit that referenced this pull request Nov 18, 2025
Upgrade Spring AI to Spring Boot 4.0.0-RC2 following the
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide

Major version upgrades:
- Spring Boot: 3.5.7 → 4.0.0-RC2
- Kotlin: 1.9.25 → 2.2.21 (with Kotlin compiler 2.2.21)
- Rest Assured: added BOM 5.5.6
- swagger-codegen-maven-plugin: 3.0.64 → 3.0.75
- Testcontainers: 1.20.4 → 2.0.1
  - Updated Elasticsearch test container to 9.2.0
  - Keep opensearch-testcontainers to 2.0.1 for Java 17 compatibility
  - Gemfire Testcontainers: 2.3.0 → 2.3.3

Spring Boot package reorganization:
- MongoDB: o.s.b.autoconfigure.mongo → o.s.b.mongodb.autoconfigure
- Data Redis: o.s.b.autoconfigure.data.redis → o.s.b.data.redis.autoconfigure
- JDBC: o.s.b.autoconfigure.jdbc → o.s.b.jdbc.autoconfigure
- Cassandra: o.s.b.autoconfigure.cassandra → o.s.b.cassandra.autoconfigure
- Neo4j: o.s.b.autoconfigure.neo4j → o.s.b.neo4j.autoconfigure
- Couchbase: o.s.b.autoconfigure.couchbase → o.s.b.couchbase.autoconfigure
- RestClient: o.s.b.autoconfigure.web.client → o.s.b.restclient.autoconfigure
- WebClient: o.s.b.autoconfigure.web.reactive → o.s.b.webclient.autoconfigure
- Servlet: o.s.b.autoconfigure.web.servlet → o.s.b.web.server.autoconfigure.servlet

Spring Framework 6.x/7.x compatibility:
- Add constructors without logic to *Api classes for better extensibility

Adopt new modular design of starters:
- Added explicit spring-boot-starter-* dependencies (jdbc, cassandra, mongodb, neo4j, elasticsearch, etc.)
- Added spring-boot-starter-restclient and spring-boot-starter-webclient where needed

Use new Jackson 3.x API:
- Updated import com.fasterxml.jackson.databind.json.JsonMapper
- Modified ObjectMapper configurations for compatibility

Migrated from Spring Retry to Spring Framework Retry:
- org.springframework.retry → org.springframework.core.retry
- Updated RetryTemplate, RetryPolicy, and RetryListener APIs
- Replaced RetryCallback/RetryContext with new Retryable interface

Property Mapper API changes:
- Updated PropertyMapper null handling (changed from .whenNonNull() to direct usage)
- Applied in Couchbase and Elasticsearch vector store configurations

API changes:
- Replaced MultiValueMap<String, String> with HttpHeaders for HTTP headers
- Updated Elasticsearch client to use Rest5Client (from RestClient)
- Standardized header handling across OpenAI, Anthropic, DeepSeek, MiniMax, ZhiPuAI, Mistral AI, and other APIs
- Added overloaded constructors accepting RestClient/WebClient directly
- Updated HttpHeaders methods (.containsKey() → .get())

Testcontainers artifact naming:
- Standardized to prefixed format (e.g., junit-jupiter → testcontainers-junit-jupiter)
- Updated across all modules: Cassandra, PostgreSQL, MongoDB, Neo4j, Milvus, Qdrant, etc.

Additional improvements:
- Updated Swagger codegen templates for Huggingface model to align with latest Spring Framework APIs
- Added FailureDetectingExternalResource from old testcontainers versions for gemfire-testcontainers compatibility
- Updated Kotlin nullable type handling in extensions (reified T → reified T : Any)
- Added missing test dependencies (spring-boot-restclient-test, spring-boot-starter-jdbc-test)

Resolves: #3379

Extends and replaces: #4771, #4681

Co-authored-by: Paul Bakker <pbakker@netflix.com>

Signed-off-by: Dmitry Bedrin <dmitry.bedrin@gmail.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
@tzolov
Copy link
Contributor

tzolov commented Nov 18, 2025

Rebased, squashed and merged at d5e92be

@tzolov tzolov closed this Nov 18, 2025
Profile-exe added a commit to Profile-exe/spring-ai that referenced this pull request Nov 19, 2025
Update HuggingFace modules to align with Spring Boot 4.0.0-RC2 upgrade (spring-projects#4774)
after rebasing onto main branch:

RetryTemplate Migration (Spring Framework 7):
- Update imports from org.springframework.retry.support to org.springframework.core.retry
- Replace retryTemplate.execute(ctx -> ...) with RetryUtils.execute(retryTemplate, () -> ...)
- Rewrite HuggingfaceRetryTests to use new RetryListener interface with RetryPolicy/Retryable

RestClientAutoConfiguration Migration (Spring Boot 3.2+):
- Update imports from org.springframework.boot.autoconfigure.web.client to
  org.springframework.boot.restclient.autoconfigure
- Add spring-boot-starter-restclient dependency to autoconfigure pom.xml

Test Improvements:
- Fix beanOutputConverterRecords test with simpler prompt and lower temperature
- Ensure consistent JSON response generation

Modified Files:
- HuggingfaceChatModel.java, HuggingfaceEmbeddingModel.java (RetryUtils pattern)
- HuggingfaceRetryTests.java (complete rewrite for new API)
- HuggingfaceChatModelIT.java (test fix)
- All autoconfigure classes (RestClientAutoConfiguration import)
- autoconfigure pom.xml (new dependency)

This commit ensures compatibility with Spring Boot 4.0.0-RC2 and Spring Framework 7
following the main branch upgrade in commit d5e92be (spring-projects#4774).

Signed-off-by: Myeongdeok Kang <kang67572346@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EPIC] Spring Boot 4.0 compatability

5 participants